using System;
using System.Linq.Expressions;

namespace MathService.Expressions.Complex
{
    public sealed class ComplexPowerExpression : ComplexBinaryExpression
    {
        private Expression f_r;
        private Expression f_arg;

        private Expression r { get { return f_r ?? (f_r = Multiply(GetPower(Left.Power, Divide(Right.Re, 2)), GetPower(Math.E, Divide(Left.Arg, Right.Im)))); } }
        private Expression arg { get { return f_arg ?? (f_arg = Add(Multiply(Left.Arg, Right.Re), Multiply(GetLog(Left.Abs), Right.Im))); } }
        public ComplexPowerExpression(ComplexExpression Left, ComplexExpression Right) : base(Left, Right) { }

        protected override Expression GetRe() { return Multiply(r, GetCos(arg)); }

        protected override Expression GetIm() { return Multiply(r, GetSin(arg)); }
    }
}